
//
//  UIBarButtonItem+Extention.swift
//  我的微博练习
//
//  Created by zhangguo on 15/10/17.
//  Copyright © 2015年 zhangguo. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imageName:String,target:AnyObject?,action:String?) {
        //创建barButton从字典中取值，
        let button = UIButton()
        
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        button.sizeToFit()
        
        //设置监听方法，判断 key是否存在
        if let actionName = action {
            button.addTarget(target, action: Selector(action!), forControlEvents: UIControlEvents.TouchUpInside)
        }
    //调用制定的构造函数
        self.init(customView:button)
    
    }
}